package com.youbug.mall.member_ums.feign.impl;

import com.youbug.common.to.UmsMemberTo;
import com.youbug.common.vo.CommonSelectLongValVo;
import com.youbug.common.vo.CommonSelectVo;
import com.youbug.mall.member_ums.entity.UmsMember;
import com.youbug.mall.member_ums.entity.UmsMemberLevel;
import com.youbug.mall.member_ums.service.IUmsMemberLevelService;
import com.youbug.mall.member_ums.service.IUmsMemberService;
import com.youbug.mall.service_ucs.feign.IUcsMemberFeignService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class UcsMemberFeignServiceImpl implements IUcsMemberFeignService {

    @Autowired
    private IUmsMemberService umsMemberService;

    @Autowired
    private IUmsMemberLevelService umsMemberLevelService;

    @Override
    public UmsMemberTo getMemberTo(Long memberId) {

        UmsMember member = umsMemberService.getById(memberId);
        UmsMemberTo to = new UmsMemberTo();
        if(member!=null){
            BeanUtils.copyProperties(member, to);
            return to;
        }
        return null;
    }

    @Override
    public List<CommonSelectLongValVo> getMemberLevels() {

        List<UmsMemberLevel> levels = umsMemberLevelService.list();
        if(!CollectionUtils.isEmpty(levels)){
            return levels.stream().map(e -> {
                return new CommonSelectLongValVo(e.getName(), e.getId());
            }).collect(Collectors.toList());
        }
        return null;
    }
}
